package ace.module.sms.core.autoconfig;

import ace.cmp.jetcache.anno.config.EnableAceMethodCache;
import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslJdbcRepositoryExtendFactoryBean;
import ace.module.sms.core.impl.SmsCoreBootstrapScanner;
import ace.module.sms.core.impl.properties.SmsCoreProperties;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.stereotype.Repository;

/**
 * boostrap auto config.
 *
 * @author Caspar
 */
@EnableAceMethodCache(basePackageClasses = {SmsCoreBootstrapScanner.class})
@EnableConfigurationProperties({SmsCoreProperties.class})
@EnableJdbcRepositories(
    basePackageClasses = {ace.module.sms.core.impl.dao.repository.RepositoryScanner.class},
    repositoryFactoryBeanClass = QuerydslJdbcRepositoryExtendFactoryBean.class)
@ComponentScan(
    basePackageClasses = SmsCoreBootstrapScanner.class,
    excludeFilters = {
      @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Repository.class)
    })
@Configuration
public class SmsCoreAutoConfig {
    @Bean
    public GroupedOpenApi smsGroupedOpenApi() {
        return GroupedOpenApi.builder()
            .group("sms")
            .displayName("短信服务")
            .packagesToScan(SmsCoreBootstrapScanner.class.getPackageName())
            .build();
    }
}
